<%@ page language="java" contentType="text/html; charset=UTF-8"
		 pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
	<c:set var="ctx" value="${pageContext.request.contextPath}" />
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>狮桥分授权</title>
	<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
	<div id="pageInTab" class="pageInTab">
		<div tabid="tabA" title="狮桥分授权" lselected="true">
			<form id="formSet1" class="l-form">

				<div class="fieldset1 tabel_col clearFix">
					<div class="caption">
						<span class="title">轻卡商家报单设置</span>
					</div>
					<div class="fieldBox col_50">
						<div class="label">是否开启轻卡商家报单</div>
						<div class="field">
							<input id="declarationYes" type="radio" value="1" name="declaration" /> 是
							<input id="declarationNo" type="radio" value="0" name="declaration" /> 否
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">是否开启轻卡商家测算</div>
						<div class="field">
							<input id="estimateYes" type="radio" value="1" name="estimate" /> 是
							<input id="estimateNo" type="radio" value="0" name="estimate" /> 否
						</div>
					</div>
					<div class="btnsBox">
						<span id="savePropBtn" class="sq-button sq-button-round l-dialog-btn-ok">保存</span>
					</div>
				</div>

				<div class="fieldset1 tabel_col clearFix">
					<div class="caption">
						<span class="title">征信开关及每周可查次数</span>
						<input name="splAttrCd" id="splAttrCd" type="hidden" class="ui-textbox" value="${splAttrCd }">
					</div>
					<div class="fieldBox col_50">
						<div class="label">是否有权查询征信</div>
						<div class="field">
							<input id="isAuthCrdChkYes" type="radio" value="1" name="isAuthCrdChk" /> 是
							<input id="isAuthCrdChkNo" type="radio" value="0" name="isAuthCrdChk" /> 否
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">每周可查询征信次数</div>
						<div class="field" style="width: 100%;">
							<input name="limChkTms" id="limChkTms" type="text" class="ui-textbox" value=""
								   validate ="{number:true,required:true}"
								   <c:if test="${not empty isCheckCreditBlackList and isCheckCreditBlackList == 1}">disabled</c:if> />
						</div>
					</div>

					<div class="btnsBox">
						<c:if test="${empty isCheckCreditBlackList or isCheckCreditBlackList == 0}">
							<span id="saveCiCfgBtn" class="sq-button sq-button-round l-dialog-btn-ok">保存</span>
						</c:if>
					</div>
				</div>
				

				
				<div class="sqPanel">
					<div class="sqPanel_head inL">
						<span>维护客户经理信息</span>
					</div>
					<div class="sqPanel_body">
						<div id="ligergrid_A1" class="sq-grid"></div>
					</div>
				</div>

				<div class="sqPanel">
					<div class="sqPanel_head inL">
						<span></span>
					</div>
					<div class="sqPanel_body">
						<div id="ligergrid_A2" class="sq-grid"></div>
					</div>
				</div>
			</form>
		</div>
		<%--<div tabid="tabB" title="" id="tabBId">
			<iframe frameborder="0" name="tabB" id="tabB" src=""></iframe>
		</div>--%>
	</div>
</div>
<script type="text/javascript">
	var npSocialRlGrid=null,
			ciCfgLogGrid = null,
			splId='${splId}',
			splNm='${splNm}';
	var isCheckCreditBlackList = '${isCheckCreditBlackList}';
	var isAuthCrdChkB = 0;
	var limChkTmsB = 0;

	var pageInApp={
		flag:true
	}; // to 下一级子窗口 接口
	var pageInTab=null;
	var loadedTabs=[]
	$(function(){
		initTab();

        //保存轻卡商家配置
        $('#savePropBtn').click(function(){
			$("#readRlBtn").attr("disabled", "disabled");
            var form = liger.get("formSet1");
            var data = form.getData();
            data.splId = splId;
            data.splNm = splNm;
            var url = '<%=path%>/spl/splpropinfo/saveSplPropInfo.do';
            var wait_dialog;
            $.ajax({
                type: 'post',
                dataType:'json',
                data:data,
                url: url,
                beforeSend: function(){
                    wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
                },
                success:function(msg){
                    wait_dialog.close();
                    if(msg.success == 1){
                        $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
						ciCfgLogGrid.reload();
                    }else{
                        $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
                    }
                }
            });
        });

		//保存查征信配置
		$('#saveCiCfgBtn').click(function(){
			var form = liger.get("formSet1");
			/* if (!form.valid()) {
				$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO , SQ_type: "warning" });
				return ; //验证不通过，不执行以下代码
			} */
			var data = form.getData();
			data.splId = splId;
			data.splNm = splNm;
			data.isAuthCrdChkB = isAuthCrdChkB;
			data.limChkTmsB = limChkTmsB;
			console.log(data);
			var url = '<%=path%>/spl/splcicfg/saveCiCfg1.do';
			var wait_dialog;
			$.ajax({
				type: 'post',
				dataType:'json',
				data:data,
				url: url,
				beforeSend: function(){
					wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
				},
				success:function(msg){
					wait_dialog.close();
					if(msg.success == 1){
						$.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
						ciCfgLogGrid.reload();
					}else{
						$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
					}
				}
			});
		});

		$('#formSet1').ligerForm({
			validate : true
		});
		initSplConfigGrid();
		initCiCfgLogGrid();
		initData();

	});

	function initData(){
		var id = splId;
		if(!id){
			return;
		}
		var _url = '<%=path%>/product/splInfo/getById.do';
		$.ajax({
			type: 'get',
			dataType:'json',
			data:{id:id},
			url: _url,
			success:function(msg){
				if(msg.success == 1){
					setData(msg.data);//设置数据
				}else{
					$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
				}
			}
		});
	}
	function setData(data){
		//是否开启轻卡商家报单
		$("input[name='declaration'][value="+data.declaration+"]").prev(".l-radio").click();
		if (data.declaration) {
			declarationB = data.declaration;
		}
		//是否开启轻卡商家测算
		$("input[name='estimate'][value="+data.estimate+"]").prev(".l-radio").click();
		if (data.estimate) {
			estimateB = data.estimate;
		}
		//是否可以查询征信
		$("input[name='isAuthCrdChk'][value="+data.isAuthCrdChk+"]").prev(".l-radio").click();
		if (data.isAuthCrdChk) {
			isAuthCrdChkB = data.isAuthCrdChk;
		}
		if(isCheckCreditBlackList && isCheckCreditBlackList == '1'){
			$("input[name='isAuthCrdChk']").attr("disabled",true);

		}
		$("#limChkTms").val(data.limChkTms);
		if (data.limChkTms) {
			limChkTmsB = data.limChkTms;
		}
	};

	//初始化管理人员信息
	function initSplConfigGrid() {
		if(!splId){//供应商ID为空
			return;
		}
		npSocialRlGrid = $("#ligergrid_A1").ligerGrid({
			url: '<%=path%>/product/splUsrR/searchSplCofigInfo.do?',
			method : 'get',
			parms:{splId:splId},
			async: false,
			columns: [
				{
                    display: '业务类型', name: 'splBizTypCd', minWidth: 200,
                    valueField: 'splBizTypCd',
                    textField: 'splBizTypCdNm',
                },
				{ display: '事业部', name: 'orgDispNm', width: 300},
				{ display: '管理员', name: 'rlNm', width: 140},
				{ display: '联系方式', name: 'mp', width: 150},
				{ display: '客户经理 id', name: 'usrId', width: 150, hide: true },
				{ display: 'id', id: 'id', width: 300, hide: true },
				{ display: 'buOrgCd', id: 'buOrgCd', width: 300, hide: true },// 客户经理所属事业部
				{ display: 'org_Cd', id: 'org_Cd', width: 300, hide: true },//客户经理所属组织架构
				{ display: '设置私海状态', name: 'isPrivate', minWidth: 150,
					render: function (item) {
						return item.isPrivateCdNm;
					}
				},
				{ display: '操作', width: 130 , align:'left',
					render: function (rowdata, rowindex, value){
						var d='';

						return d;
					}
				}
			],
			pageSize:10,
	        root:'rows',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        height: 300,
			heightDiff: -2,
	        isScroll: false,
	        checkbox:false,
	        rownumbers:true,
	        allowUnSelectRow: true,
			alternatingRow: false,
			enabledSort:false,
			onAfterShowData: function() {
				SetIframe_height ();
			},
	        onRenderComplete: function () {
	        	iframeResize ();
	        },
		});
	};

	//初始化管理人员信息
	function initCiCfgLogGrid() {
		if(!splId){//供应商ID为空
			return;
		}
		ciCfgLogGrid = $("#ligergrid_A2").ligerGrid({
			url: '<%=path%>/spl/splcicfglog/initListByOneData.do?',
			method : 'get',
			parms:{
				dataId:splId,
				dataTabNm : 'SPL_BSC_INFO'
			},
			async: false,
			columns: [
				{
					display: '操作时间', name: 'crtTm', width: 150,
					render : function (rowdata, index, value) {
						return renderDate(rowdata, index, value);

					}
				},
				{ display: '操作者', name: 'crtUsrNm', width: 100},
				{ display: '是否开启轻卡商家报单', name: 'declaration', width: 150,
					render : function (rowdata, index, value) {
						if (rowdata.declaration == rowdata.declarationB) {
							return '————';
						} else {
							return rowdata.declarationBNm + "--" + rowdata.declarationNm;
						}
					}
				},
				{ display: '是否开启轻卡商家测算', name: 'estimate', width: 150,
					render : function (rowdata, index, value) {
						if (rowdata.estimate == rowdata.estimateB) {
							return '————';
						} else {
							return rowdata.estimateBNm + "--" + rowdata.estimateNm;
						}
					}
				},
				{ display: '是否有权查征信', name: 'isAuthCrdChk', width: 150,
					render : function (rowdata, index, value) {
						if (rowdata.isAuthCrdChk == rowdata.isAuthCrdChkB) {
							return '————';
						} else {
							return rowdata.isAuthCrdChkBNm + "--" + rowdata.isAuthCrdChkNm;
						}
					}
				},
				{ display: '每周可查询征信次数', name: 'limChkTms', width: 150,
					render : function (rowdata, index, value) {
						if (rowdata.limChkTms == rowdata.limChkTmsB) {
							return '————';
						} else {
							return rowdata.limChkTmsB + "--" + rowdata.limChkTms;
						}
					}
				},
			],
			pageSize:10,
			root:'rows',
			record:'total',
			hideLoadButton : true,
			width: '100%',
			height: 300,
			heightDiff: -2,
			isScroll: false,
			checkbox:false,
			rownumbers:true,
			allowUnSelectRow: true,
			alternatingRow: false,
			enabledSort:false,
			onAfterShowData: function() {
				SetIframe_height ();
			},
			onRenderComplete: function () {
				iframeResize ();
			},
		});
	};

	//格式化时间
	function renderDate(rowdata, index, value) {
		var dateStr = "";
		if (null != value) {
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
		}
		return dateStr;
	}

	function iframeResize () {
	    if (parent.parent.mainApp) {
	        parent.parent.mainApp.parentTab.onResize();
	    };
	};
	
	//初始化Tab
	function initTab(){
		pageInTab = $("#pageInTab").ligerTab({
			height: 'auto',
			contextmenu: false,
			minIframeHeight: GET_minIframeHeight(),
			onBeforeSelectTabItem: function (tabid) {
				if(tabid!="tabA"){

				}
			},
			onAfterSelectTabItem: function(tabid) {
				if (loadedTabs.indexOf(tabid)<0) {
					loadedTabs.push(tabid);
					switch (tabid){
						case "tabB":
							pageInTab.setTabItemSrc(tabid, "");
							break;
					}
				};
				SetIframe_height();
			}
		});

		$.extend(true, pageInApp, {
			pageInTab: pageInTab
		});
	};
</script>
</body>
</html>
